/**
 * @brief tcp连接
 */

#pragma once
#include <atomic>
#include <string>

#include "mallocSharedPtr.hpp"
#include "dataCh.hpp"
class tcpServer;

class tcpConnection : public dataCh
{
private:
	std::atomic< int >     m_fd__;
	union{
		sockaddr_in    m_addr;
		sockaddr_in6   m_addr6;
	}peerAddr__;
	tcpServer            * p_svr__;
private:
	
public:
	tcpConnection( int fd , sockaddr_in * addr , size_t addrLen , tcpServer * svr );
	~tcpConnection();

	virtual nativeH_t native_handle() final{ return m_fd__.load(); }
	/**
	 * @brief 处理连接请求。接受连接后发出连接成功通知，通知参数提供新的连接对象指针
	 */
	virtual void onReadyRead( const uint8_t* data , size_t len ) final;

	void close();
	/**
	 */
	void send( const char * data , size_t len );
	
	void send( wheels::mallocSharedPtr< char >& data );
};
